Remove ESM generated code #40
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Details
lib/instead of both ESM and CommonJS code.tscto generate CommonJS code and TypeScript declaration files inlib/.Why???
src/folder, thentscwill generate 'js' files rather than '.mjs' files, and that means problems with loaders/bundlers that assume that '.js' files contain CommonJS and then they fail to process them because those '.js' files contain 'import/export' rather than 'require/module.exports'.srcthentscwill generate.mjswith ESM code but it's literally impossible to have anothertsconfig-cjs.jsonfile to maketscgenerate CommonJS code with ".js" or ".cjs" extension.importandrequire()calls in the generated ESM and CJS code inlib/, which is terrible. But then Babel also generates.js.mapfiles that reference a.mtsfile inlib/folder which obviously doesn't exist.tscto generate TypeScript declaration files and, since we have '.mts' files insrc/, those declaration files haved.mtsextension. But they many text editors and TypeScript consumers asusme that declaraion files must be '.d.ts' only. And if we rename their extension then we have also to munge generated.mjs(ESM) and.cjsfiles inlib/because those files contain special commented mapping lines that reference the declaration file (with '.d.mts').import foo from './foo.ts'rather thanfrom './foo'. So here another needed rewrite in generatedlib/code.Conclusion
.tsor.mtsextension in source files, whether to import internal files with or without extension, andtsconfig.jsondoesn't expose options enough to cover all cases we need when generating ESM or CJS code. I've checked them all, and the same with Babel.